<?php

/*
 * 	Codificado: 02-Noviembre-2011, 18:05
	Estado: Ajustado_Modelo_Actual(X) Funcionando()
 */


class PlanesInternacionales_Model extends CI_Model{

	private $table = 'PlanesInternacionales';

	function _required($required, $data)
	{
		foreach($required as $field)
		if(!isset($data[$field])) return false;

		return true;
	}

	function Insertar($options = array()) {

		/*if ($this->_required(array('IdInvestigacion','IdInvestigador','TipoInvestigador'), $options))
		return FALSE ;*/

		$this->db->insert($this->table, $options);
		return $this->db->insert_id();

	}

	function Editar($options = array()) {

		if(!$this->_required(array('IdPlanes'),$options))
		return FALSE;

		unset($options['submit'] );

		if(isset($options['Area']))
		$this->db->set('Area', $options['Area']);

		if(isset($options['Estrategia']))
		$this->db->set('Estrategia', $options['Estrategia']);

		if(isset($options['Estado']))
		$this->db->set('Estado', $options['Estado']);

		if(isset($options['Unidad']))
		$this->db->set('Unidad', $options['Unidad']);

		if(isset($options['Programa']))
		$this->db->set('Programa', $options['Programa']);

		if(isset($options['Unidad']))
		$this->db->set('Unidad', $options['Unidad']);
		
		
		$this->db->where('IdPlanes', $options['IdPlanes']);
		$this->db->update($this->table, $options);

		return $this->db->affected_rows();
	}

	function Eliminar($options = array()) {

		$this->db->where('IdPlanes', $options['IdPlanes']);
		$this->db->delete($this->table);

		if($data['error'] = $this->db->_error_message());
		return $data;

	}

	function Ver($options = array()) {

		$this->db->where('IdPlanes', $options['IdPlanes']);
		$query = $this->db->get($this->table);

		if(isset($options['IdPlanes']))
		return $query->row_array(0);

		return $query->result_array();
	}

	function Listar($options = array()) {

		$this->db->select('IdPlanes,Area,Estrategia,Actividad' );

		if(isset($options['limit']) && isset($options['offset']))
		$this->db->limit($options['limit'], $options['offset']);
		else if(isset($options['limit']))
		$this->db->limit($options['limit']);
			
		$query = $this->db->get($this->table);
		if(isset($options['count']))
		return $query->num_rows();
			
		return $query->result_array();
	}


	function BuscarPorAno($options = array()) {
		if ($this->_required(array('Ano'), $options)) return FALSE ;

		$this->db->where('Ano', $options['Ano']);
		$query = $this->db->get($this->table);

		return $query->result_array();
	}

}
